/**
 * @(#)ITaskHandler.java 2018年4月26日
 */
package com.mz.mattress.client.task;

import com.alibaba.fastjson.support.spring.FastJsonRedisSerializer;
import com.mz.mattress.api.util.JacksonUtils;
import com.mz.mattress.client.task.handler.MemberNewStepTaskHandler;
import com.mz.mattress.client.task.pojo.MemberStepBean;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public interface TaskHandler<T> {

    void handler(T data);


    public static void main(String[] args) {

//        try {

        MemberStepBean stepBean = new MemberStepBean();
        stepBean.setCurrStep(3);
        stepBean.setTotalStep(5);
        stepBean.setMobile("dd");

//        Jackson2JsonRedisSerializer<MemberStepBean> serializer = new Jackson2JsonRedisSerializer<MemberStepBean>(MemberStepBean.class);
//        byte[] serialize = serializer.serialize(stepBean);
//        MemberStepBean bean = serializer.deserialize(serialize);
//        System.out.println(bean.getMobile());


            FastJsonRedisSerializer<MemberStepBean> serializer = new FastJsonRedisSerializer<>(MemberStepBean.class);
            byte[] serialize = serializer.serialize(stepBean);
            MemberStepBean obj = serializer.deserialize(serialize);
            System.out.println(obj.getMobile());


        // 获取GenericClass的Class对象
//            Class<?> clazz = Class.forName("com.mz.mattress.client.task.handler.MemberNewStepTaskHandler");
//            Constructor<?> constructor = clazz.getDeclaredConstructor();
//            constructor.setAccessible(true);
//            MemberNewStepTaskHandler handler = (MemberNewStepTaskHandler) constructor.newInstance();
//
//            String json = JacksonUtils.toJson(stepBean);
//            System.out.println(json);

//            Class<?> clazz2 = Class.forName("com.mz.mattress.client.task.pojo.MemberStepBean");
//            MemberStepBean obj = JacksonUtils.toObj(json, clazz2.get);
//            System.out.println(obj.getMobile());

//            MemberStepBean obj = JacksonUtils.toObj(json, MemberStepBean.class);
//            System.out.println(obj.getMobile());


//            Class<?> clazz2 = Class.forName("com.mz.mattress.client.task.pojo.MemberStepBean");
//
//            Constructor<?> declaredConstructor = clazz2.getDeclaredConstructor();
//            declaredConstructor.setAccessible(true);
//            MemberStepBean memberStepBean = (MemberStepBean) declaredConstructor.newInstance();
//
//            handler.handler(memberStepBean);


//			Class<?> genericClass = Class.forName("MemberNewStepTaskHandler");
//			// 获取带有一个String参数的构造函数
//			Constructor<?> constructor = genericClass.getConstructor(String.class);
//			// 使用构造函数创建GenericClass的实例，这里传递一个String类型的参数
//			Object instance = constructor.newInstance("Hello, World!");
//			// 确保实例的类型是正确的
//			if (instance instanceof TaskHandler) {
//				GenericClass<String> genericInstance = (GenericClass<String>) instance;
//				System.out.println(genericInstance.getData()); // 输出: Hello, World!
//			}
//        } catch (ClassNotFoundException | NoSuchMethodException | InstantiationException |
//                 IllegalAccessException | InvocationTargetException e) {
//            e.printStackTrace();
//        }

    }
}
